﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using tour.szhome.common;
using TOUR.SZHOME.Attributes;
using TOUR.SZHOME.BLL;
using TOUR.SZHOME.Entity;

namespace tour.szhome.manage.area.Controllers
{
    [SelfOnly]
    public class NewsController : Controller
    {
        //
        // GET: /News/
        Projects_NewBLL _newsbll = new Projects_NewBLL();

        /// <summary>
        ///  项目所属动态列表视图
        /// </summary>
        /// <param name="id">项目ID</param>
        /// <param name="pname">项目名称</param>
        /// <returns></returns>
        public ActionResult Index(int id = 0, string pname = "")
        {
            ViewBag.ID = id;
            ViewBag.PName = pname;
            return View();
        }

        /// <summary>
        /// 动态编辑
        /// </summary>
        /// <param name="id">动态ID</param>
        /// <returns></returns>
        public ActionResult Edit(int id = 0, int pid = 0, string pname = "")
        {
            Projects_NewEntity model = new Projects_NewEntity();
            if (id > 0)
            {
                model = _newsbll.GetNewsByID(id);
            }
            ViewBag.ID = id;
            ViewBag.PID = pid;
            ViewBag.PName = pname;
            return View(model);
        }

        /// <summary>
        /// 动态编辑
        /// </summary>
        /// <returns></returns>
        [ActionName("json_edit")]
        public ActionResult Json_Edit(Projects_NewEntity model)
        {
            model.FBSJ = Convert.ToDateTime(model.FBSJ);
            return Json(_newsbll.EditNews(model));
        }

        /// <summary>
        /// 获取项目下的动态列表 -- 分页
        /// </summary>
        /// <param name="projectId"></param>
        /// <param name="page"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        [ActionName("get_news_list")]
        public ActionResult GetNewsList(int projectId = 0, int page = 1, int size = 10)
        {
            PageSet pageSet = new PageSet()
            {
                PageIndex = page,
                PageSize = size,
            };
            var data = new
            {
                page = page,
                pageSize = size,
                list = _newsbll.GetNewsListByPID(projectId, pageSet),
                recordCount = pageSet.RecordCount,
                totalpage = pageSet.PageCount
            };
            return Json(data);
        }

        /// <summary>
        /// 根据ID删除对象
        /// </summary>
        /// <param name="nid"></param>
        /// <returns></returns>
        [ActionName("json_delete")]
        public ActionResult DelByID(int nid)
        {
            return Json(_newsbll.DelByID(nid), JsonRequestBehavior.AllowGet);
        }
    }
}
